import { getToken, setToken } from '@/utils/auth'
import { getUserAvatar, getUserInfo } from '@/api/user'
export default {
  namespaced: true,
  state: {
    token: getToken(),
    userInfo: {}
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
      setToken(token)
    },
    getUser(state, info) {
      state.userInfo = { ...info }
    },
    reomveUser(state) {
      state.userInfo = {}
    }
  },
  actions: {
    async getUserStore(content) {
      const res = await getUserInfo()
      // console.log(res)
      content.commit('getUser', res.data)
      const info = await getUserAvatar(res.data.userId)
      // console.log(info.data)
      content.commit('getUser', { ...res.data, ...info.data })
      // console.log(res.data.roles.menus)
      return res.data.roles.menus
    }

  },
  getters: {}
}
